package Clothing.controller.returns;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import Clothing.bean.BaseResponse;
import Clothing.bean.request.lease.EditLeaseByIdRequest;
import Clothing.bean.request.lease.GetAllLeaseRequest;
import Clothing.bean.request.returns.AddReturnRequest;
import Clothing.bean.respose.returns.GetAllReturnResponse;
import Clothing.service.returns.ReturnService;
import Clothing.util.ResultModel;

@Controller
@RequestMapping(value = "/Return")
public class ReturnController {
    

    @Resource
    private ReturnService returnService;
    
    @ResponseBody
    @RequestMapping(value = "/getAllReturn" ,method = RequestMethod.POST)
    public ResultModel getAllReturn(@RequestBody GetAllLeaseRequest request){
        ResultModel resultModel = new ResultModel();
        GetAllReturnResponse response = new GetAllReturnResponse();
        int result = returnService.getAllReturn(request,response);
        switch (result) {
            case 0:
                response.setSuccess("0");
                break;
            case 1:
                response.setSuccess("1");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;
    }
    
    @ResponseBody
    @RequestMapping(value = "/editReturnById",method = RequestMethod.POST)
    public ResultModel editReturnById(@RequestBody EditLeaseByIdRequest request){
        ResultModel resultModel = new ResultModel();
        BaseResponse response = new BaseResponse();
        int result = returnService.editReturnById(request);
        switch (result) {
            case 0:
                response.setSuccess("1");
                break;
            case 1:
                response.setSuccess("0");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;
    }
    
    
    @ResponseBody
    @RequestMapping(value = "/addReturn" , method = RequestMethod.POST)
    public ResultModel addReturn(@RequestBody AddReturnRequest request){
        ResultModel resultModel = new ResultModel();
        BaseResponse response = new BaseResponse();
        int result = returnService.addReturn(request);
        switch (result) {
            case 0:
                response.setSuccess("0");
                break;
            case 1:
                response.setSuccess("1");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;
    }
}
